﻿<!DOCTYPE HTML>
<html>
<head>
<include file="public/header" />
<style>
	.table tr td{
		text-align:center !important;
	}
	.table tr td:nth-child(3),.table tr td:nth-child(4){
		text-align:left !important;
	}
	
	tbody tr:hover{
		background:#f1f1f1;
	}
</style>
<title>权限管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 权限管理 <a class="btn btn-refresh btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a href="javascript:;" onclick="admin_permission_del_all()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
			<a href="javascript:;" onclick="admin_permission_add('添加权限节点','{:url('User/addpermission')}','','400')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加权限节点</a>
		</span> 
	</div>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="7">权限节点</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="40">ID</th>
				<th width="200">权限名称</th>
				<th>规则</th>
				<th width="200">权限状态</th>
				<th width="100">是否菜单</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
			<volist name="permission" id="v">
				<tr class="text-c">
					<td><input type="checkbox" value-name="{$v.name}" value="{$v.id}"></td>
					<td>{$v.id}</td>
					<td>{$v.title}</td>
					<td>{$v.name}</td>
					<td><if condition='$v["status"] eq 1'><span style='color:green;'>已启用</span><else/><span style='color:red;'>已停用</span></if></td>
					<td><if condition='$v["menu"] eq 1'><span style='color:green;'>是</span><else/><span style='color:#cdcdcd;'>否</span></if></td>
					<td>
						<a title="编辑" href="javascript:;" onclick="admin_permission_edit('权限编辑','{:url('User/addpermission')}','{$v.id}','','400')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i>编辑</a> 
						<a title="删除" href="javascript:;" onclick="admin_permission_del(this,'{$v.id}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i>删除</a></td>
				</tr>
				<if condition="isset($v['list'])">
					<volist name="$v.list" id="v2">
						<tr class="text-c">
							<td><input type="checkbox" value-name="{$v2.name}" value="{$v2.id}"></td>
							<td>{$v2.id}</td>
							<td><span style='padding:0 15px;'>&nbsp;</span><img src="__STATIC__/image/line.png" /> {$v2.title}</td>
							<td><span style='padding:0 15px;'>&nbsp;</span><img src="__STATIC__/image/line.png" /> {$v2.name}</td>
							<td><if condition='$v2["status"] eq 1'><span style='color:green;'>已启用</span><else/><span style='color:red;'>已停用</span></if></td>
							<td><if condition='$v2["menu"] eq 1'><span style='color:green;'>是</span><else/><span style='color:#cdcdcd;'>否</span></if></td>
							<td>
								<a title="编辑" href="javascript:;" onclick="admin_permission_edit('权限编辑','{:url('User/addpermission')}','{$v2.id}','','400')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i>编辑</a> 
								<a title="删除" href="javascript:;" onclick="admin_permission_del(this,'{$v2.id}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i>删除</a>
							</td>
						</tr>
						<if condition="isset($v2['list'])">
							<volist name="$v2.list" id="v3">
								<tr class="text-c">
									<td><input type="checkbox" value-name="{$v3.name}" value="{$v3.id}"></td>
									<td>{$v3.id}</td>
									<td><span style='padding:0 30px;'>&nbsp;</span><img src="__STATIC__/image/line.png" /> {$v3.title}</td>
									<td><span style='padding:0 30px;'>&nbsp;</span><img src="__STATIC__/image/line.png" /> {$v3.name}</td>
									<td><if condition='$v3["status"] eq 1'><span style='color:green;'>已启用</span><else/><span style='color:red;'>已停用</span></if></td>
									<td><if condition='$v3["menu"] eq 1'><span style='color:green;'>是</span><else/><span style='color:#cdcdcd;'>否</span></if></td>
									<td>
										<a title="编辑" href="javascript:;" onclick="admin_permission_edit('权限编辑','{:url('User/addpermission')}','{$v3.id}','','400')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i>编辑</a> 
										<a title="删除" href="javascript:;" onclick="admin_permission_del(this,'{$v3.id}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i>删除</a>
									</td>
								</tr>
							</volist>
						</if>
					</volist>
				</if>
			</volist>
		</tbody>
	</table>
</div>
<include file="public/footer" />
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript">
/*管理员-权限-添加*/
function admin_permission_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-权限-编辑*/
function admin_permission_edit(title,url,id,w,h){
	layer_show(title,url+"?id="+id,w,h);
}

/*删除权限*/
function admin_permission_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url("User/delpermission")}',
			dataType: 'json',
			data:{"id":id},
			success: function(data){
				if(data.error=="success"){
					$(obj).parents("tr").remove();
					layer.msg('已删除!',{icon:6,time:1000});
				}else{
					layer.msg(data.error,{icon:5,time:1000});
				}
			},
			error:function(data) {
				layer.msg('操作失败!'+data.responseText,{icon:5,time:1000});
			},
		});		
	});
}
function admin_permission_del_all(){
	layer.confirm('确认要删除选中的权限吗？',function(index){
		//遍历所有复选框
		var dataarr=[];
		$("tbody input[type='checkbox']").each(function(){
			if($(this).prop("checked")){
				dataarr.push({"id":$(this).val()})
			}
		})
		if(dataarr.length<=0){
			layer.msg("请至少选择一条记录在操作",{icon:5,time:1000});
			return;
		}

		$.ajax({
			type: 'POST',
			url: '{:url("User/delpermissionAll")}',
			dataType: 'json',
			data:{"id":dataarr},
			success: function(data){
				if(data.error=="success"){
					layer.msg('已删除!',{icon:6,time:1000});
					setTimeout(function(){
						location.replace(location.href);
					},1500);
				}else{
					layer.msg(data.error,{icon:5,time:1000});
				}
			},
			error:function(data) {
				layer.msg('操作失败!'+data.responseText,{icon:5,time:1000});
			},
		});		
	});
}
</script>
<script src="__STATIC__/js/auth.js"></script>
</body>
</html>